x
turtles-own[ covid_positive? ;; true if the individual currently has covid-19 wearing_mask? ;; true if the individual is wearing a mask remaining_immunity_weeks ;; weeks of immunity left for the individual infection_duration ;; duration in weeks the individual has been infected individual_age ;; age of the individual in weeks vaccinated? ] ;; vaccination statusglobals[ percent_positive ;; what percent of the population is covid-positive percent_immune ;; what percent of the population is immune individual_lifespan ;; expected lifespan of an individual reproduction_odds ;; odds of an individual reproducing each tick environment_capacity ;; carrying capacity of the environment immunity_period ;; how long immunity lasts, in weeks vaccine_effectiveness_reduction ] ;; reduction in infection chance due to vaccination;; initialize the modelto setupclear-alldefine_parametersinitialize_populationcalculate_statisticsvisualize_populationreset-ticksend;; create a set number of individuals with some initially covid-positiveto initialize_populationlet num_vaccinated round((percent_vaccinated / 100) * population)create-turtles population [ set shape "person" setxy random-xcor random-ycor set individual_age random individual_lifespan set infection_duration 0 set remaining_immunity_weeks 0 set size 1.5 ;; makes individuals easier to spot regain_health set wearing_mask? random-float 100 < people-masked set vaccinated? false ] ;; Ensure all turtles start as not vaccinatedask n-of 10 turtles [ become_infected ]ask n-of num_vaccinated turtles [ vaccinate ]end;; procedures to change the state of health of the individualsto become_infectedset covid_positive? trueset remaining_immunity_weeks 0endto regain_healthset covid_positive? falseset remaining_immunity_weeks 0set infection_duration 0endto develop_immunityset covid_positive? falseset infection_duration 0set remaining_immunity_weeks immunity_periodend;; set up model constantsto define_parametersset individual_lifespan 50 * 52 ;; lifespan in weeksset environment_capacity 300set reproduction_odds 0.01 ;; 1% reproduction chanceset immunity_period 52 ;; immunity lasts one yearset social-distancing 10 ;; intial level of social distancingset vaccine_effectiveness_reduction 0.18 ;; 82% reduction in infection chance due to vaccinationend;; main model loopto goask turtles [ age_individual random_move if covid_positive? [ resolve_infection ] ifelse covid_positive? [ transmit_virus ] [ reproduce ]]calculate_statisticsvisualize_populationtickend;; update statistics for the populationto calculate_statisticsif count turtles > 0 [ set percent_positive (count turtles with [ covid_positive? ] / count turtles) * 100 set percent_immune (count turtles with [ is_immune? ] / count turtles) * 100 ]end;; update visuals based on health statusto visualize_populationask turtles[ set color ifelse-value covid_positive? [ red ] [ ifelse-value is_immune? [ grey ] [ ifelse-value vaccinated? [ blue ] [ green ] ] ] ]end;; procedures to manage individual aging and health statusto age_individualset individual_age individual_age + 1if individual_age > individual_lifespan [ die ]if is_immune? [ set remaining_immunity_weeks remaining_immunity_weeks - 1 ]if covid_positive? [ set infection_duration infection_duration + 1 ]endto random_move ;; makes individuals move randomlylet move-distance 1ifelse any? other turtles in-radius 3[ let distance-factor (100 - social-distancing) / 100 set move-distance move-distance * distance-factor][ set move-distance 1]rt random 100lt random 100fd move-distanceend;; handling virus transmission with mask and season modifiersto transmit_virusask turtles [ if mask-effectiveness < 0.1 [set mask-effectiveness 0.1] ] ask other turtles-here with [ not covid_positive? and not is_immune? ][ let effective_transmission_modifier transmission_modifier if wearing_mask? [ set effective_transmission_modifier effective_transmission_modifier * mask-effectiveness ] if vaccinated? [ set effective_transmission_modifier effective_transmission_modifier * vaccine_effectiveness_reduction ] if random-float 100 < (infectiousness * effective_transmission_modifier) / (ifelse-value wearing_mask? [mask-effectiveness] [1]) [ become_infected ]]end;; resolution of infection, individuals recover or perishto resolve_infectionif infection_duration > duration [ ifelse random-float 100 < recovery-rate [ develop_immunity ] [ die ] ]end;; reproduction logic based on environment capacityto reproduceif count turtles < environment_capacity and random-float 100 < reproduction_odds [ hatch 1 [ set individual_age 1 lt 45 fd 1 regain_health ] ]endto-report transmission_modifierlet modifier 1ifelse current-season = "Winter" [ set modifier 1.56] [ set modifier 0.54]report modifierend;; report immunity statusto-report is_immune?report remaining_immunity_weeks > 0endto vaccinateset vaccinated? trueend;; ensure parameters are defined for the user interface elementsto startupdefine_parameters ;; sets up constants used in the interfaceend